package com.leo.erp.web.log;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.leo.erp.dto.LogExecution;
import com.leo.erp.entity.Log;
import com.leo.erp.enums.LogStateEnum;
import com.leo.erp.service.LogService;
import com.leo.erp.util.HttpServletRequestUtil;

@Controller
@RequestMapping(value = "/log")
public class LogManagementController {
	@Autowired
	private LogService logService;
	
	@RequestMapping(value = "/list")
	@ResponseBody
	public Map<String, Object> list(HttpServletRequest request){
		Map<String, Object> modelMap = new HashMap<>();
		//获取前台传过来的值
		String operation = HttpServletRequestUtil.getString(request, "operation");
		int userId = HttpServletRequestUtil.getInt(request, "usernameID");
		String clientIP = HttpServletRequestUtil.getString(request, "clientIp");
		int status = HttpServletRequestUtil.getInt(request, "status");
		String beginTime = HttpServletRequestUtil.getString(request, "beginTime");
		String endTime = HttpServletRequestUtil.getString(request, "endTime");
		String contentDetails = HttpServletRequestUtil.getString(request, "contentdetails");
		int currentPage = HttpServletRequestUtil.getInt(request, "currentPage");
		int pageSize = HttpServletRequestUtil.getInt(request, "pageSize");
		
		Log log = new Log();
		log.setOperation(operation);
		log.setUserID(userId);
		log.setClientIP(clientIP);
		log.setStatus(status);
		log.setBeginTime(beginTime);
		log.setEndTime(endTime);
		log.setContentDetails(contentDetails);
		
		LogExecution le = new LogExecution();
		//调用方法进行分页查询
		le = logService.getLogList(log, currentPage, pageSize);
		if(le.getState() == LogStateEnum.SUCCESS.getState()) {
			modelMap.put("success", true);
			modelMap.put("pages",le.getPages());//总页数
			modelMap.put("total", le.getTotal());//总数
			
			Map<String, Object> map = new HashMap<>();
			map.put("rows", le.getLogPageList());
			map.put("total", le.getTotal());
			//modelMap.put("logList", le.getLogPageList());
			modelMap.put("logList", map);
		}else {
			modelMap.put("success", false);
			modelMap.put("msg", "查询列表失败");
		}
		
		return modelMap;
	}
	
	
	
	
	
	
	
	
	
	
	
	
}
